---
title: Shopping Mall directory
description: Building a shopping mall directory
keywords:
  - electrodb
  - docs
  - concepts
  - dynamodb
  - query
  - entity
  - attribute
  - schema
  - index
layout: ../../../layouts/MainLayout.astro
---

Let's look at the needs of application used to manage Shopping Mall properties. The application assists employees in the day-to-day operations of multiple Shopping Malls.

## Requirements

1. As a Maintenance Worker, I need to know which stores are currently in each Mall down to the Building they are located.
2. As a Helpdesk Employee, I need to locate related stores in Mall locations by Store Category.
3. As a Property Manager, I need to identify upcoming leases in need of renewal.

## Example Setup

import ExampleSetup from "../../../partials/entity-query-example-setup.mdx";

<ExampleSetup />

## Mutations

### Add a new Store to the Mall

```typescript
await StoreLocations.create({
  mallId: "EastPointe",
  storeId: "LatteLarrys",
  buildingId: "BuildingA1",
  unitId: "B47",
  category: "spite store",
  leaseEndDate: "2020-02-29",
  rent: "5000.00",
}).go();
```

Returns the following:

```json
{
  "data": {
    "mallId": "EastPointe",
    "storeId": "LatteLarrys",
    "buildingId": "BuildingA1",
    "unitId": "B47",
    "category": "spite store",
    "leaseEndDate": "2020-02-29",
    "rent": "5000.00",
    "discount": "0.00"
  }
}
```

---

### Change the Stores Lease Date

When updating a record, you must include all **Composite Attributes** associated with the table's _primary_ **PK** and **SK**.

```typescript
let storeId = "LatteLarrys";
let mallId = "EastPointe";
let buildingId = "BuildingA1";
let unitId = "B47";

await StoreLocations.patch({ storeId, mallId, buildingId, unitId })
  .set({ leaseEndDate: "2021-02-28" })
  .go();
```

Returns the following:

```json
{
  "data": {
    "leaseEndDate": "2021-02-28"
  }
}
```

### Retrieve a specific Store in a Mall

When retrieving a specific record, you must include all **Composite Attributes** associated with the table's _primary_ **PK** and **SK**.

```typescript
let storeId = "LatteLarrys";
let mallId = "EastPointe";
let buildingId = "BuildingA1";
let unitId = "B47";

await StoreLocations.get({ storeId, mallId, buildingId, unitId }).go();
```

Returns the following:

```json
{
  "data": {
    "mallId": "EastPointe",
    "storeId": "LatteLarrys",
    "buildingId": "BuildingA1",
    "unitId": "B47",
    "category": "spite store",
    "leaseEndDate": "2021-02-28",
    "rent": "5000.00",
    "discount": "0.00"
  }
}
```

#### Remove a Store location from the Mall

When removing a specific record, you must include all **Composite Attributes** associated with the table's _primary_ **PK** and **SK**.

```typescript
let storeId = "LatteLarrys";
let mallId = "EastPointe";
let buildingId = "BuildingA1";
let unitId = "B47";
let storeId = "LatteLarrys";

await StoreLocations.delete({ storeId, mallId, buildingId, unitId }).go();
```

Returns the following:

```json
{ "data": {} }
```

## Queries

### All Stores in a particular mall

Fulfilling [Requirement #1](#shopping-mall-requirements).

```typescript
let mallId = "EastPointe";

let stores = await StoreLocations.query.units({ mallId }).go();
```

### All Stores in a particular mall building

Fulfilling [Requirement #1](#shopping-mall-requirements).

```typescript
let mallId = "EastPointe";
let buildingId = "BuildingA1";

let stores = await StoreLocations.query.units({ mallId, buildingId }).go();
```

### Find the store located in unit B47

Fulfilling [Requirement #1](#shopping-mall-requirements).

```typescript
let mallId = "EastPointe";
let buildingId = "BuildingA1";
let unitId = "B47";

let stores = await StoreLocations.query
  .units({ mallId, buildingId, unitId })
  .go();
```

### Stores by Category at Mall

Fulfilling [Requirement #2](#shopping-mall-requirements).

```typescript
let mallId = "EastPointe";
let category = "food/coffee";

let stores = await StoreLocations.query
  .units({ mallId })
  .where((attr, op) => op.eq(attr.category, category))
  .go();
```

### Stores by upcoming lease

Fulfilling [Requirement #3](#shopping-mall-requirements).

```typescript
let storeId = "LatteLarrys";
let q2StartDate = "2020-04-01";

let stores = await StoreLocations.query
  .leases({ storeId })
  .lt({ leaseEndDate: q2StartDate })
  .go();
```

### Stores will renewals for Q4

Fulfilling [Requirement #3](#shopping-mall-requirements).

```typescript
let storeId = "LatteLarrys";
let q4StartDate = "2020-10-01";
let q4EndDate = "2020-12-31";

let stores = await StoreLocations.query
  .leases({ storeId })
  .between({ leaseEndDate: q4StartDate }, { leaseEndDate: q4EndDate })
  .go();
```

### Spite-stores with release renewals this year

Fulfilling [Requirement #3](#shopping-mall-requirements).

```typescript
let storeId = "LatteLarrys";
let yearStarDate = "2020-01-01";
let yearEndDate = "2020-12-31";
let storeId = "LatteLarrys";

let stores = await StoreLocations.query
  .leases({ storeId })
  .between({ leaseEndDate: yearStarDate }, { leaseEndDate: yearEndDate })
  .where((attr, op) => op.eq(attr.category, "Spite Store"))
  .go();
```

### All Latte Larry's in a particular mall building

```typescript
let mallId = "EastPointe";
let buildingId = "BuildingA1";
let unitId = "B47";
let storeId = "LatteLarrys";

let stores = await StoreLocations.query
  .units({ mallId, buildingId, storeId })
  .go();
```
